package com.rdtravel.converters;

import com.rdtravel.entities.Destination;
import com.rdtravel.services.DestinationsService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.converter.Converter;

public class StringToDestinationConverter implements Converter<String, Destination> {
	private final DestinationsService destinationsService;
	
	@Autowired
	public StringToDestinationConverter(DestinationsService destinationsService) {
		this.destinationsService = destinationsService;
	}


	@Override
	public Destination convert(String destinationName) {
		if (destinationName == null || destinationName.isEmpty()) {
			return null;
		}
		return destinationsService.findByName(destinationName);
	}
	

}
